/*
 * @(#)ErrorSqlList.java   1.0  2021年11月24日
 * 
 * Copyright (c)	2014-2020. All Rights Reserved.	GuangZhou hhmk Technology Company LTD.
 */
package com.swift.dts.service;

import java.util.LinkedList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.swift.core.auth.Login;
import com.swift.core.model.ServiceRequest;
import com.swift.core.model.data.DataModel;
import com.swift.core.model.data.MapDataModel;
import com.swift.core.service.SynInterface;
import com.swift.dts.dao.ErrorSqlTableDao;
import com.swift.dts.dao.model.ErrorSqlTable;
import com.swift.dts.dao.model.ErrorSqlTableKey;
import com.swift.util.type.TypeUtil;

/**
 * 添加说明 
 * @author zhengjiajin
 * @version 1.0 2021年11月24日
 */
@Service("errorSqlList")
@Login
public class ErrorSqlList implements SynInterface {

    @Autowired
    private ErrorSqlTableDao errorSqlTableDao;
    /** 
     * @see com.swift.core.service.SynInterface#doService(com.swift.core.model.ServiceRequest)
     */
    @Override
    public DataModel doService(ServiceRequest req) {
        DataModel res = new MapDataModel();
        ErrorSqlTableKey key =new ErrorSqlTableKey();
        key.setDataSource(req.getData().getString("data_source"));
        key.setDbName(req.getData().getString("db_name"));
        key.setDestination(req.getData().getString("destination"));
        key.setTableName(req.getData().getString("table_name"));
        int page = TypeUtil.toInt(req.getData().getObject("page"), 1);
        int pageSize = TypeUtil.toInt(req.getData().getObject("pageSize"), 10);
        int start = (page-1)*10;
        int count = errorSqlTableDao.count(key);
        List<ErrorSqlTable> list = errorSqlTableDao.list(key, start, pageSize);
        if(list==null) list = new LinkedList<ErrorSqlTable>();
        res.addObject("total", count);
        res.addObject("list", list);
        return res;
    }

}
